Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

255
Visualizações
extract only index with the value of "date" from a JSON file with javascript

I am accessing a JSON file with nodejs api request.

the file file has 1000's of data.

var data = fileData[0].data has the "date" values in multiple objects. The objects have two values "date" and "value". I just want to print the "date" values of the whole data variable.

"idNumber": "98745973459479574935794577345",
    "data": [
        {
            "date": "2001-09-12T08:37:09.009Z",
            "value": 307479
        },
        {
            "date": "2001-09-12T08:36:53.919Z",
            "value": 307478
        },
        {
            "date": "2001-09-12T08:36:38.809Z",
            "value": 307477
        },

There are thousands of these objects within the array. I just want to print all the "date". I tried console.log(data[0]) but it would print the first value and it will also include the "value" which I don't want.

is it possible to print every index with the keyword of "date"? If so, how?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

data.forEach(item=>{
console.log(item.date)
})
about 4 years ago · Juan Pablo Isaza Relatório

0

You need to iterate whole array in order to get the date value.

You can use for loop, while loop, foreach etc, to iterate.

For Each Loop:

let data = [
        {
            "date": "2001-09-12T08:37:09.009Z",
            "value": 307479
        },
        {
            "date": "2001-09-12T08:36:53.919Z",
            "value": 307478
        },
        {
            "date": "2001-09-12T08:36:38.809Z",
            "value": 307477
        },
]

data.forEach(i => {
    console.log(i.date)
})

For Loop:

    let data = [
            {
                "date": "2001-09-12T08:37:09.009Z",
                "value": 307479
            },
            {
                "date": "2001-09-12T08:36:53.919Z",
                "value": 307478
            },
            {
                "date": "2001-09-12T08:36:38.809Z",
                "value": 307477
            },
    ]

    
    for(let i = 0; i < data.length; i++){
        console.log(data[i].date)
    }

about 4 years ago · Juan Pablo Isaza Relatório

0

Map seems to be a good method for you

NOTE I name the outer object obj so to get the data I use obj.data

const obj = {
  "idNumber": "98745973459479574935794577345",
  "data": [{
      "date": "2001-09-12T08:37:09.009Z",
      "value": 307479
    },
    {
      "date": "2001-09-12T08:36:53.919Z",
      "value": 307478
    },
    {
      "date": "2001-09-12T08:36:38.809Z",
      "value": 307477
    }
  ]
}
console.log(obj.data.map(({date}) => date).join(','))

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda